<?php
namespace app\admin\model;
use think\Model;
use think\Db;

class BusChannelTempReview extends Model
{
	public function getAll($request)
	{
		if($request['check_onoff']){
			$where[] = ['check_onoff' , '=' , $request['check_onoff']];
		}else{
			$where[] = ['check_onoff' , '=' , 0];
		}

		if($request['temp_id']){
			$where[] = ['temp_id' , '=' , trim($request['temp_id'])];
		}

		return $this->alias('rv')
		->field('rv.*,c.company_name')
		->join('bus_channel c','rv.cid=c.channel_id')
		->where($where)
		->paginate($request['limit'])
		->each(function($item, $key) {
			switch ($item->check_onoff) {

                    case 0:
                        $item->check_onoff = '<span class="layui-badge layui-bg-gray">待审</span>';
                        break;
                    case 1:
                        $item->check_onoff = '<span class="layui-badge layui-bg-green">成功</span>';
                        break;
                    case 2:
                        $item->check_onoff = '<span class="layui-badge ">失败</span>';
                        break;
                }

            $item->content = '<div style="width:360px">';

            $list = db('bus_plat_temp_frame')->where('temp_id' , $item->temp_id)->order('frame,part')->select();

            foreach ($list as $k => $v) {
            	if($v['type'] == 1)
            	{
            		$item->content .= $v['content'] . '<br>';
            	}else{
            		$item->content .= '<img src="' . $v['content'] . '"  style="width:100%"><br>';
            	}
            }

            $item->content .= '</div>';

            $item->cid = $item->cid . '/' . $item->company_name;
		})->toArray();
	}
}